package com.goods.controller.business;

import com.goods.business.service.CategoryService;
import com.goods.business.service.ProductService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.business.QueueMap;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;
import java.util.List;
import java.util.Map;

/**
 * 物资来源
 */
@Api(tags = "业务管理-物资来源接口")
@RestController
@RequestMapping("/business/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    //加载物资资料列表
    @GetMapping("/findProductList")
    public ResponseBean findProductList(@RequestParam Map<String,Object> map){
        PageVO<ProductVO> pageVO = productService.findProductList(map);
        return ResponseBean.success(pageVO);
    }

    //添加物资信息
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductVO productVO){
        productService.add(productVO);
        return ResponseBean.success();
    }

    //打开编辑物资页面
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ProductVO productVO = productService.edit(id);
        return ResponseBean.success(productVO);
    }

    //修改物资资料
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody ProductVO productVO){
        productService.update(productVO);
        return ResponseBean.success();
    }

    //把物资移入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        productService.remove(id);
        return ResponseBean.success();
    }

    //把物资从回收站中恢复
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        productService.back(id);
        return ResponseBean.success();
    }

    //从回收站中删除物资
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        productService.delete(id);
        return ResponseBean.success();
    }

    //物资审核
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        productService.publish(id);
        return ResponseBean.success();
    }

    //加载可入库的商品列表
    @GetMapping("/findProducts")
    public ResponseBean findProducts(@RequestParam Map<String,Object> map){
        PageVO<ProductVO> pageVO = productService.findProducts(map);
        return ResponseBean.success(pageVO);
    }

    //物资库存页面加载库存信息和柱状图显示
    @GetMapping("/findProductStocks")
    public ResponseBean findProductStocks(@RequestParam Map<String,Object> map){
        PageVO<ProductVO> pageVO = productService.findProductStocks(map);
        return ResponseBean.success(pageVO);
    }

    //物资所有的库存信息和饼状图显示
    @GetMapping("/findAllStocks")
    public ResponseBean findAllStocks(@RequestParam Map<String,Object> map){
        PageVO<ProductVO> pageVO = productService.findProductStocks(map);
        return ResponseBean.success(pageVO.getRows());
    }
}
